/*
* Copyright @ 2014 com.iflysse.trains
* manger_v2.0 上午9:49:55
* All right reserved.
*
*/
package com.iflysse.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.iflysse.dao.MenuInfoDao;
import com.iflysse.pojo.MenuInfo;
import com.iflysse.utils.MySessionFactory;

/**
 * @desc: manger_v2.0
 * @author: wql
 * @createTime: 2014年11月26日 上午9:49:55
 * @history:
 * @version: v1.0
 */
public class MenuInfoService {
	private SqlSessionFactory sf;

	public MenuInfoService() {
		sf = MySessionFactory.getSessionFactory();
	}
	
	public List<MenuInfo> findAllMenu() {
		SqlSession session = sf.openSession();
		List<MenuInfo> menuList=null;
		try {
			MenuInfoDao dao = (MenuInfoDao) session.getMapper(MenuInfoDao.class);
			menuList = dao.findAllMenu();
		} finally {
			session.close();
		}
		return menuList;
	}
	
	/**
	 * 通过角色id找到对应中间表中的菜单id的列表
	 */
	public List<MenuInfo> findMenusByRoleId(int rid) {
		SqlSession session = sf.openSession();
		List<MenuInfo> menuList=null;
		try {
			MenuInfoDao dao =session.getMapper(MenuInfoDao.class);
			menuList = dao.findMenusByRoleId(rid);
			
			
		} finally {
			session.close();
		}
		return menuList;
	}

	public MenuInfo findById(int mid) {
		SqlSession session = sf.openSession();
		MenuInfoDao dao = session.getMapper(MenuInfoDao.class);
		return dao.findById(mid);
	}
}
